<?php
class UnitTestCase_Unfuddle_Api extends UnitTestCase_Unfuddle {

    public function setUp() {
    
        Mock::generate('Unfuddle_Auth');
    
    }
    
    public function testGetUriWithOnlySubdomain() {
    
        $api = new Unfuddle_Api('foo');
        $url = $api->getUri();
        $this->assertEqual($url, 'http://foo.unfuddle.com/api/v1');
    
    }
    
    public function testGetUriWithSubdomainAndSecure() {
    
        $api = new Unfuddle_Api('foo', true);
        $url = $api->getUri();
        $this->assertEqual($url, 'https://foo.unfuddle.com/api/v1');
    
    }
    
    public function testGetUriWithSubdomainAndSecureAndApiVersion() {
    
        $api = new Unfuddle_Api('foo', true);
        $api->setApiVersion(3);
        $url = $api->getUri();
        $this->assertEqual($url, 'https://foo.unfuddle.com/api/v3');
    
    }
    
    /**
     * The URI doesn't actually change when authenticated so this isn't necessary
     */
    public function testGetUriWithAuth() {
    
        $testauth = new MockUnfuddle_Auth();
        $testauth->setReturnValue('getUsername', 'username');
        $testauth->setReturnValue('getPassword', 'password');
        $api = new Unfuddle_Api('foo');
        $api->authenticate($testauth);
        $url = $api->getUri();
    
    }
    
    public function testSetOtherScheme() {
    
        $api = new Unfuddle_Api('foo');
        $api->setScheme('email');
        $this->assertEqual($api->getUri(), 'email://foo.unfuddle.com/api/v1');
    
    }
    
    public function testSetDomainAfterConstruct() {
    
        $api = new Unfuddle_Api(null);
        $this->assertEqual($api->getUri(), 'http://.unfuddle.com/api/v1');
        $api->setDomain('test');
        $this->assertEqual($api->getUri(), 'http://test.unfuddle.com/api/v1');
    
    }
    
    /**
     * The following are use cases gleaned from users and from myself
     */
    
    /**
     * Was looking to put an Unfuddle dashboard for myself. I am currently
     * monitoring 4 different Unfuddle accounts with over a dozen projects
     * between them. Had in mind to put a dashboard that will give me a top
     * view of mine and others' tasks and priorities and some statistics.
     *
     * If there's a core that does work I don't mind to start working with
     * it and possibly finish up some things. I'd hate to start developing
     * from scratch something that's already out there.
     */
    /*public function testiGALsUseCase() {
    
        // Initialize the client
        $client = new Unfuddle_Api();
        
        // Define each of the accounts I want to work with
        $accounts = array(
            'isitlegit' => array(
                'subdomain' => 'isitlegit',
                'username' => 'luke',
                'password' => '8ateball',
                'project_id' => 2, // The project I want to work with
            ),
            'lukevisinoni' => array(
                'subdomain' => 'lukevisinoni',
                'username' => 'luke',
                'password' => '8ateball',
                'project_id' => 1, // The project I want to work with
            ),
        );
        
        foreach ($accounts as $name => $params) {
            // Create connection objects for each account I want to work with
            $auth = new Unfuddle_Auth($params['subdomain'], $params['username'], $params['password']);
            $request = new Unfuddle_Request("/projects/{$params['project_id']}/people", 'GET', array('Accept: application/xml', 'Content-type: application/xml'));
            $request->setQueryParam('truncate', 25); // set query parameter to send as part of GET request
            // $request->setPostParam('truncate', 25); // this is the POST equivalent of the above method
            $response = $client->dispatch($request, $auth);
            $output = $response->getBody();
            $people = $response->transform('Person'); // pass in the name of a model to transform the response into model objects
            // If we were to transform a response that contained only a single person, the syntax would be the same...
            // $person = $response->transform('Person');
            foreach ($people as $person) {
                // we now have a person object we can work with very easily...
                $name = $person->getProperty('name');
                // we also have shortcut methods for this...
                $name = $person->getName();
            }
        }
    
    }*/

}
